package cn.lbw.yht.poi.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lbw.yht.poi.core.Excel;
import cn.lbw.yht.poi.domain.UserDto;

public class AnnotationUtil {

	public static AnnotationUtil anno = null;  
	  
    public static AnnotationUtil getInstance() {  
        if (anno == null) {  
            anno = new AnnotationUtil();  
        }  
        return anno;  
    }  
  
    /** 
     * 读取注解值 
     *  
     * @param annotationClasss 处理Annotation类名称 
     * @param annotationField 处理Annotation类属性名称 
     * @param className 处理Annotation的使用类名称 
     * @return 
     * @throws Exception 
     */  
    @SuppressWarnings("all")  
    public  List<Map> loadVlaue(String className) throws Exception {  
        List<Map> paramList = new ArrayList<Map>();
    	 
        Field[] Fields = Class.forName(className).getDeclaredFields();
        
        for (Field field : Fields) {  
        	Excel p = field.getAnnotation(Excel.class);
        	Map<String, String> map = new HashMap<String, String>(); 
        	String excelName = p.name();
        	String excelFormart = p.timeFormat();
        	String filedName = field.getName();
        	map.put("name", excelName);
        	map.put("excelFormart", excelFormart);
        	map.put("filedName",filedName);
        	paramList.add(map);
        }  
        System.out.println(paramList);
        return paramList;  
    }  
    /**
     * 
     * @param fileName
     * @param c
     * @return
     */
    public static String findExcelFormartByfileName(String fileName,Object c){
    	try {
    		
    		return c.getClass().getDeclaredField(fileName).getAnnotation(Excel.class).timeFormat();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    	return "";
    }
  
    public static void main(String[] args) throws Exception {  
  
    	
        AnnotationUtil.getInstance().loadVlaue(UserDto.class.getName());  
    }  
}
